package com.li.common;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Dbutil {
	private Connection conn = null;
	private PreparedStatement pst = null;
	private ResultSet rs = null;
	public static String Driver = "com.mysql.jdbc.Driver";
	public static String Url    = "jdbc:mysql://localhost:3306/talk?useUnicode=true&characterEncoding=GBK";
	public static String Dbname = "root";
	public static String Dbpass = "root123";
	
	public Connection getConn() throws SQLException,ClassNotFoundException{
		Class.forName(Driver);
		return DriverManager.getConnection(Url,Dbname,Dbpass);
		
	}
	
	
	public void closeAll() {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (pst != null) {
			try {
				pst.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
